

package com.loong.loong.hik.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.loong.loong.common.core.util.R;
import com.loong.loong.common.log.annotation.SysLog;
import com.loong.loong.hik.entity.WatchFeedback;
import com.loong.loong.hik.service.WatchFeedbackService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.loong.loong.common.excel.annotation.ResponseExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 巡更信息反馈
 *
 * @author jinyiang
 * @date 2023-03-30 14:35:01
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/watchfeedback" )
@Api(value = "watchfeedback", tags = "巡更信息反馈管理")
public class WatchFeedbackController {

    private final  WatchFeedbackService watchFeedbackService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param watchFeedback 巡更信息反馈
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('hik_watchfeedback_view')" )
    public R getWatchFeedbackPage(Page page, WatchFeedback watchFeedback) {
        return R.ok(watchFeedbackService.page(page,
				Wrappers.query(watchFeedback).lambda()
//						新增查询
		.like(StringUtils.isNotEmpty(watchFeedback.getWatchNo()),WatchFeedback::getWatchNo,watchFeedback.getWatchNo())
		.between(StringUtils.isNotEmpty
				(watchFeedback.getStartTime())&&StringUtils.isNotEmpty
				(watchFeedback.getEndTime()),WatchFeedback::getCreateTime,watchFeedback.getStartTime(),watchFeedback.getEndTime())));
    }
    /**
     * 通过id查询巡更信息反馈
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_watchfeedback_view')" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(watchFeedbackService.getById(id));
    }

    /**
     * 新增巡更信息反馈
     * @param watchFeedback 巡更信息反馈
     * @return R
     */
    @ApiOperation(value = "新增巡更信息反馈", notes = "新增巡更信息反馈")
    @SysLog("新增巡更信息反馈" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('hik_watchfeedback_add')" )
    public R save(@RequestBody WatchFeedback watchFeedback) {
        return R.ok(watchFeedbackService.save(watchFeedback));
    }

    /**
     * 修改巡更信息反馈
     * @param watchFeedback 巡更信息反馈
     * @return R
     */
    @ApiOperation(value = "修改巡更信息反馈", notes = "修改巡更信息反馈")
    @SysLog("修改巡更信息反馈" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('hik_watchfeedback_edit')" )
    public R updateById(@RequestBody WatchFeedback watchFeedback) {
        return R.ok(watchFeedbackService.updateById(watchFeedback));
    }

    /**
     * 通过id删除巡更信息反馈
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除巡更信息反馈", notes = "通过id删除巡更信息反馈")
    @SysLog("通过id删除巡更信息反馈" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_watchfeedback_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(watchFeedbackService.removeById(id));
    }


    /**
     * 导出excel 表格
     * @param watchFeedback 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('hik_watchfeedback_export')" )
    public List<WatchFeedback> export(WatchFeedback watchFeedback) {
        return watchFeedbackService.list(Wrappers.query(watchFeedback));
    }
}
